package com.wkhyapp.lm.adapter;


import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.wkhyapp.lm.R;
import com.wkhyapp.lm.http.vo.Goods;
import com.wkhyapp.lm.utils.ImageLoadUtil;
import com.wkhyapp.lm.utils.StringUtils;

import java.util.List;

/**
 * Created by Administrator on 2021-10-6.
 */

public class GoodsListAdapter extends BaseQuickAdapter<Goods, BaseViewHolder> {

    public GoodsListAdapter.callBack mCallBack;
    public GoodsListAdapter(int layoutResId, List<Goods> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, final Goods item) {
        ImageView imageView = helper.getView(R.id.goods_iv);
        ImageLoadUtil.setRoundImage_Normal(mContext,item.getImg(),6,imageView);
        if(!StringUtils.isEmpty(item.getPrice())){
            if(Double.parseDouble(item.getPrice())>1){
                helper.setText(R.id.price_tv,"￥"+item.getPrice());
            }else{
                helper.setText(R.id.price_tv,"");
            }

        }else{
            helper.setText(R.id.price_tv,"");
        }
        
        helper.setText(R.id.title_tv,item.getDesc());
        TextView button = helper.getView(R.id.share_but);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCallBack.view(item);
            }
        });
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCallBack.share(item);
            }
        });
        RelativeLayout down_rl = helper.getView(R.id.down_rl);
        helper.setText(R.id.imgCount_tv,item.getImgCount()+"");
        down_rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCallBack.down(item);
            }
        });
        helper.getView(R.id.goos_rl).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCallBack.info(item);
            }
        });

    }
    public void  setCallBack(GoodsListAdapter.callBack callBack){
        this.mCallBack = callBack;
    }


    public interface  callBack{

        void down(Goods item);

        void share(Goods item);

        void view(Goods item);

        void info(Goods item);
    }

}
